<template>
      <div>
      <el-button type="primary" @click="willadd" class="btn">添加</el-button>

      <v-list :list="list" @init="init" @edit="edit"></v-list>

      <v-form :info="info" :list="list" @init="init" ref="f"></v-form>
  </div>
</template>

<script>
import vList from "./components/list.vue"
import vForm from "./components/form.vue"
import {reqmenulist} from "../../request/api"
export default {
  components:{
    vList,
    vForm
  },
  data(){
    return {
      info:{
        isshow:false,
        isadd:true
      },
      list:[]
    }
  },
  methods:{
    willadd(){
      this.info.isshow=true;
      this.info.isadd=true;
    },
    init() {
      reqmenulist({istree:true}).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.list;
        }
      });
    },
    edit(id){
      this.info.isshow=true;
      this.info.isadd=false;
      //ref 父元素获取子元素的实例
      this.$refs.f.one(id)
    }
  },
  mounted(){
    this.init()
  }
}
</script>

<style>
.btn{
  margin-bottom: 20px;
}
</style>